#ifndef RESOURCES_HEADER_INCLUDED
#define RESOURCES_HEADER_INCLUDED

#include "util.h"

#include <allegro5/allegro.h>
#define FOLDER_IMAGES "img"

#include <vector>
#include <string>
#include <utility>

class ALLEGRO_BITMAP;
class ALLEGRO_FONT;
class GameBoard;
class Block;

typedef std::vector<Block*>  rowBlock;
typedef std::vector< rowBlock > matrixBlock;

class Resources{

    private:
        const char* mapsFile;
        std::vector<ALLEGRO_BITMAP*> _images;
        std::vector<GameBoard*> _boards;
        std::vector<ALLEGRO_FONT*> _fonts;

        static Resources* _instance;
        static bool _instanceFlag;
        Resources(){ mapsFile = "mapas.txt";}

        int _num_stages;

        void load();
        void loadImages();
        void loadMaps();
        void loadFonts();

        void writeMaps();

        ALLEGRO_FONT* loadFont(std::string name, int size);
        ALLEGRO_BITMAP* loadImage(std::string name);

    public:
        static Resources* instance();

        inline int num_stages(){return (int) _boards.size();};
        void save_stage(int stage,GameBoard* gb);

        enum e_Images{ FLOOR, BOX, BOX_OK, WALL, TARGET, EMPTY, PLAYER_UP, PLAYER_RIGHT, PLAYER_DOWN, PLAYER_LEFT, P_NOTHING, P_NORTH, P_SOUTH, P_IRON, BACKGROUND , TOOLBOX };
        enum e_Block{ TYPE_TILE_BLOCK = 'B', TYPE_TILE_FLOOR = 'F', TYPE_TILE_WALL = 'W',TYPE_TILE_TARGET = 'T', TYPE_TILE_EMPTY='E',TYPE_BLOCK_NORTH ='N',TYPE_BLOCK_SOUTH = 'S',TYPE_BLOCK_IRON = 'I',TYPE_BLOCK_WOOD = 'W',TYPE_BLOCK_NONE = '-' };
        enum e_Fonts{ FONT_SUPER_MARIO };

        inline ALLEGRO_BITMAP* image(Resources::e_Images imgIndex){ return Resources::_instance->_images[imgIndex]; };
        inline ALLEGRO_FONT* font(Resources::e_Fonts fontIndex){ return Resources::_instance->_fonts[fontIndex]; };
        inline GameBoard* board(int _stage){ return _boards.at(_stage); };
};


#endif
